<%--
  Created by IntelliJ IDEA.
  User: kkk
  Date: 2022/10/6
  Time: 16:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery.js"></script>
    <base href="${pageContext.request.contextPath}/">
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <style>
        tr th{
            background-color: cornflowerblue;
        }
        tr:nth-child(odd){
            background-color: powderblue;
        }
        a{
            text-decoration: none;
        }
        h1{
            margin-left: 150px;
        }
    </style>
</head>
<body>
<table border="1">
    <h1>新能源汽车电池信息</h1>
    <tr>
        <th>编号</th>
        <th>车型</th>
        <th>所属城市</th>
        <th>使用单位</th>
        <th>压差报警器</th>
        <th>报警时间</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${power}" var="porwer">
        <tr id="${porwer.id}">
            <td><a href="PowerSelectIdServlet?id=${porwer.id}">${porwer.id}</a></td>
            <td>${porwer.carName}</td>
            <td>${porwer.cityName}</td>
            <td>${porwer.userName}</td>
            <td>${porwer.pressureValue}</td>
            <td>${porwer.time}</td>
            <td><a href="javascript:void(0)" onclick="del(${porwer.id})">删除</a></td>
        </tr>
    </c:forEach>
</table>

</body>
<script>
    function del(id){
        if (confirm("确定要删除吗？")){
            $.get("PowerDelServlet","id="+id,function (data){
                if (data==="true"){
                    alert("删除成功！");
                    location.href="PowerListServlet";
                }else {
                    alert("删除失败！");
                }
            })
        }
    }
</script>
</html>
